package tests;

import gameComponents.Player;
import gamePieces.King;

import java.awt.Point;
import java.util.ArrayList;

import junit.framework.TestCase;

/**
 * 
 */

/**
 * @author SELMAN
 *
 */
public class KingTest extends TestCase {

	Player p = new Player(1);
	King k = new King(0,0,p);
	/**
	 * @param name
	 */
	public KingTest(String name) {
		super(name);
	}

	/* (non-Javadoc)
	 * @see junit.framework.TestCase#setUp()
	 */
	protected void setUp() throws Exception {
		super.setUp();
	}

	/* (non-Javadoc)
	 * @see junit.framework.TestCase#tearDown()
	 */
	protected void tearDown() throws Exception {
		super.tearDown();
	}

	/**
	 * Test method for {@link King#checkIfLegal(int, int)}.
	 * @author Selman Selman
	 */
	public final void testCheckIfLegal() {
		//check if checkIfLegal would return true if king moves 1 step vertically
		assertTrue(k.checkIfLegal(0,1));
		//check if checkIfLegal would return true if king moves 1 step horizantally
		assertTrue(k.checkIfLegal(1,0));
		//check if checkIfLegal would return true if king moves 1 step diagonally
		assertTrue(k.checkIfLegal(1,1));
		//check if checkIfLegal would return false if King moves any other way then the three mentioned at the top
		assertFalse(k.checkIfLegal(1, 3));
		//check if checkIfLegal would return false if king moves out of boundaries
		assertFalse(k.checkIfLegal(9, 9));
	}

	/**
	 * Test method for {@link Piece#getX()}.
	 * @author Selman Selman
	 */
	public final void testGetX() {
		//since king is created initially at (0,0)
		//getX() should return 0
		assertEquals(k.getX(),0);
	}

	/**
	 * Test method for {@link Piece#getY()}.
	 * @author Selman Selman
	 */
	public final void testGetY() {
		//since king is created initially at (0,0)
		//getY() should return 0
		assertEquals(k.getY(),0);
	}

	/**
	 * Test method for {@link Piece#setX(int)}.
	 * @author Selman Selman
	 */
	public final void testSetX() {
		k.setX(1); // set x coordinate to 1
		//check that x is now 1
		assertEquals(k.getX(),1);
	}

	/**
	 * Test method for {@link Piece#getOwnership()}.
	 * @author Selman Selman
	 */
	public final void testGetOwnership() {
		//get Ownership should return object p
		assertEquals(k.getOwnership(),p);
	}

	/**
	 * Test method for {@link Piece#setY(int)}.
	 * @author Selman Selman
	 */
	public final void testSetY() {
		k.setY(1); // set y coordinate to 1
		//check that y is now 1
		assertEquals(k.getY(),1);
	}

	/**
	 * Test method for {@link Piece#getMoves()}.
	 * @author Selman Selman
	 */
	public final void testGetMoves() {
		k.possibleMoves();
		ArrayList<Point> p = k.getMoves(); //gets possible moves
		//checks that array list of possible moves contains every single possible move
		assertTrue(p.contains(new Point(1,0)));
		assertTrue(p.contains(new Point(0,1)));
		assertTrue(p.contains(new Point(1,1)));
		//makes sure it does not contain a wrong possible move
		assertFalse(p.contains(new Point(3,3)));
	}

	/**
	 * Test method for {@link Piece#move(int, int)}.
	 * @author Selman Selman
	 */
	public final void testMove() {
		//checks if king will move 1 step diagonally
		// no need to check every single possible move since it is done in testCheckIfLegal
		k.move(1,1);
		assertEquals(k.getX(),1);
		assertEquals(k.getY(), 1);
		
		//new x and y coordinates are 1 and 1 respectively 
		//check if king will not move anywhere any direction more than 1 step
		k.move(1,3); // knight should not move
		assertEquals(k.getX(),1);
		assertEquals(k.getY(),1);
		
		k.move(3,1); //knight should not move
		assertEquals(k.getX(),1);
		assertEquals(k.getY(),1);
		
		//move knight out of boundaries
		k.move(9,9); //knight should not move
		assertEquals(k.getX(),1);
		assertEquals(k.getY(),1);
	}

}
